// jquery设置初始化
$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});

$('.post-audit').click(function (event) {
    var target = $(event.target);
    var post_id = target.attr('post-id');
    var status = target.attr('post-action-status');

    $.ajax({
        url: '/admin/posts/' + post_id + '/status',
        method: 'post',
        data: {
            status,
        },
        dataType: 'json',
        success: function (res) {
            if (res.code !== 0) {
                alert(res.msg);
            } else {
                // 移除该条数据
                target.parent().parent().remove();
            }
        }
    })
});


$('.resource-delete').click(function (event) {
    if (confirm('确认删除该专题？') === false) {
        return;
    }

    var target = $(event.target);
    var url = target.attr('delete-url');

    $.ajax({
        url: url,
        method: 'delete',
        dataType: 'json',
        success: function (res) {
            if (res.code !== 0) {
                alert(res.msg);
            } else {
                // 移除该条数据
                target.parent().parent().remove();
            }
        }
    });
});